<template>
	<view>
		<view class="" v-for="(item, index) in swipeList" :key="index">
			<fui-swipeaction-group>
				<fui-swipe-action @click="deleteItme(item)" @change="change">
					<fui-list-cell :padding="['36rpx','32rpx']" :highlight="false">
						<view class="">
							<view class="contenx">
								<uni-tag v-if="item.isDefault==true" size="mini" text="默认" type="error" />
								{{ item.location }}
							</view>
							<view class="content-text">{{ item.street }}</view>
							<view class="contenx">
								{{ item.recipientPhone }} <text
									style="color: black;margin-left: 1rem;">{{item.recipientName}}</text>
							</view>
						</view>
						<view @click="godetil(item)" class="" style="width:2rem;height: 2rem">
							<image style="width: 100%;height: 100%;" src="../../../static/adderss/detil.png"
								mode="widthFix"></image>
						</view>
					</fui-list-cell>
				</fui-swipe-action>
			</fui-swipeaction-group>
		</view>
		<u-empty v-if="swipeList.length==0" mode="address" icon="http://cdn.uviewui.com/uview/empty/address.png">
		</u-empty>

		<button class="btn" type="warn" @click="goadder">添加收货地址</button>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				show: true,
				isOpened: 'none',
				options2: [{
					text: '收藏',
					style: {
						backgroundColor: '#3c9cff'
					}
				}, {
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
				swipeList: [],
				options: [{
						text: '取消',
						style: {
							backgroundColor: '#007aff'
						}
					},
					{
						text: '确认',
						style: {
							backgroundColor: '#F56C6C'
						}
					}
				],
			};

		},
		mounted() {
			this.loadData()
		},
		onLoad() {


		},

		computed: {

			userId() {

				return this.$store.state.uid
			}
		},
		methods: {
			swipeChange(e, index) {
				console.log('返回：', e);
				console.log('当前索引：', index);
			},
			goadder() {
				uni.redirectTo({
					url: "/pages/tabBar/adderss/newAdderss/newAdderss?type=add"
				})
			},
			godetil(item) {

				uni.redirectTo({
					url: "/pages/tabBar/adderss/newAdderss/newAdderss?type=edit&data=" + JSON.stringify(item)
				})
			},
			handleItemClick(e) {
				console.log(e);
				this.isOpened = e;
				// 处理点击列表项的逻辑
			},
			async loadData() {
				// 构建请求参数
				const param = {
					current: 1,
					size: 10,
					userId: this.userId
				};

				// 发送请求
				const res = await this.$request.get('/system/address/list', param);
				console.log(res);
				if (res.code == 200) {
					// 如果请求成功，可以根据接口返回的数据做相应处理
					// 例如更新列表数据等
					this.swipeList = res.data.list.records
				}
			},
			deleteItme(e) {
				console.log(e);
				this.deteteid(e)
			},
			async deteteid(e) {
				console.log(e);
				// 构建请求参数
				const param = {
					...e
				}
				// 发送请求
				const res = await this.$request.post('/system/address/delete/id', param);
				console.log(res);
				if (res.code == 200) {
					this.swipeList = this.swipeList.filter(item => item.addressId !== e.addressId);
				}
			},
			bindClick(e) {
				console.log(e);
				uni.showToast({
					title: `点击了${e.position === 'left' ? '左侧' : '右侧'} ${e.content.text}按钮`,
					icon: 'none'
				});
			},
			change(e) {
				this.isOpened = e;
				console.log('返回：', e);
			},
			swipeClick(e, index) {
				console.log(e);
				// uni.showToast({
				// 	title: `点击了${e.position === 'left' ? '左侧' : '右侧'} ${e.content.text}按钮`,
				// 	icon: 'none'
				// });
			},
		}
	}
</script>

<style lang="scss">
	.content-box {
		flex: 1;
		/* #ifdef APP-NVUE */
		justify-content: center;
		/* #endif */
		height: auto;
		line-height: 17px;
		padding: 0.3rem 15px;
		position: relative;
		background-color: #fff;
		border-bottom-color: #f5f5f5;
		border-bottom-width: 1px;
		border-bottom-style: solid;
	}

	.contenx {
		font-size: 0.9rem;
		color: #737373;
	}

	.content-text {
		font-size: 17px;
	}

	.btn {
		position: fixed;
		bottom: 0;
		width: 100%;
	}

	.u-page {
		padding: 0;
	}

	.u-demo-block__title {
		padding: 10px 0 2px 15px;
	}

	.swipe-action {
		&__content {
			padding: 25rpx 0;

			&__text {
				font-size: 15px;
				color: $u-main-color;
				padding-left: 30rpx;
			}
		}
	}
</style>